/*     */ package com.zimbra.cs.account.callback;
/*     */ 
/*     */ import com.zimbra.common.account.ZAttrProvisioning.MailMode;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.AttributeCallback;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import java.net.InetAddress;
/*     */ import java.net.UnknownHostException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class LocalBind
/*     */   extends AttributeCallback
/*     */ {
/*     */   public void preModify(CallbackContext context, String attrName, Object attrValue, Map attrsToModify, Entry entry)
/*     */     throws ServiceException
/*     */   {}
/*     */   
/*     */   public void postModify(CallbackContext context, String attrName, Entry entry)
/*     */   {
/*  45 */     if ((entry instanceof Server)) {
/*  46 */       Server server = (Server)entry;
/*  47 */       if (attrName.equals("zimbraAdminBindAddress")) {
/*  48 */         String address = server.getAttr("zimbraAdminBindAddress", true);
/*     */         try {
/*  50 */           if ((address == null) || (address.isEmpty())) {
/*  51 */             server.setAdminLocalBind(false);
/*     */           } else {
/*     */             InetAddress inetAddress;
/*     */             try {
/*  55 */               inetAddress = InetAddress.getByName(address);
/*     */             } catch (UnknownHostException e) {
/*  57 */               server.setAdminLocalBind(false);
/*  58 */               return;
/*     */             }
/*  60 */             if ((inetAddress.isAnyLocalAddress()) || (inetAddress.isLoopbackAddress())) {
/*  61 */               server.setAdminLocalBind(false);
/*     */             } else
/*  63 */               server.setAdminLocalBind(true);
/*     */           }
/*     */         } catch (ServiceException se) {
/*  66 */           ZimbraLog.misc.warn("Unable to update zimbraAdminLocalBind " + se);
/*     */         }
/*  68 */         return;
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  76 */     List<Server> serverList = new ArrayList();
/*  77 */     if ((entry instanceof Config)) {
/*     */       try {
/*  79 */         serverList = Provisioning.getInstance().getAllServers();
/*     */       } catch (ServiceException se) {
/*  81 */         ZimbraLog.misc.warn("Unable to get server list " + se);
/*     */       }
/*  83 */     } else if ((entry instanceof Server)) {
/*  84 */       serverList.add((Server)entry);
/*     */     }
/*     */     
/*  87 */     if ((attrName.equals("zimbraMailMode")) || (attrName.equals("zimbraMailBindAddress")) || (attrName.equals("zimbraMailSSLBindAddress")))
/*     */     {
/*     */ 
/*  90 */       for (Server server : serverList) {
/*     */         try {
/*  92 */           ZAttrProvisioning.MailMode mailMode = server.getMailMode();
/*  93 */           if (mailMode == null)
/*  94 */             mailMode = Provisioning.getInstance().getConfig().getMailMode();
/*  95 */           if ((mailMode == null) || (!mailMode.isHttps()))
/*     */           {
/*  97 */             String address = server.getAttr("zimbraMailBindAddress", true);
/*  98 */             if ((address == null) || (address.isEmpty())) {
/*  99 */               server.setMailLocalBind(false);
/*     */             } else {
/*     */               InetAddress inetAddress;
/*     */               try {
/* 103 */                 inetAddress = InetAddress.getByName(address);
/*     */               } catch (UnknownHostException e) {
/* 105 */                 server.setMailLocalBind(false); }
/* 106 */               continue;
/*     */               
/* 108 */               if ((inetAddress.isAnyLocalAddress()) || (inetAddress.isLoopbackAddress())) {
/* 109 */                 server.setMailLocalBind(false);
/*     */               } else {
/* 111 */                 server.setMailLocalBind(true);
/*     */               }
/*     */             }
/*     */           } else {
/* 115 */             server.setMailLocalBind(true);
/*     */           }
/*     */         } catch (ServiceException e) {
/* 118 */           ZimbraLog.misc.warn("Unable to set zimbraMailLocalBind " + e);
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/callback/LocalBind.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */